"use strict";
const chooseLocation = requirePlugin('chooseLocation');

Page({
  data: {
    checked: false,
    address: "",
    locationName: "",
    cityText: '',
    cityValue: [],
    dateText: '',
    dateValue: [],
    citys: [
      { label: '实习', value: '实习' },
      { label: '校招', value: '校招' },
      { label: '兼职', value: '兼职' },
    ],
  },

 
  onUnload () {
    // 页面卸载时设置插件选点数据为null，防止再次进入页面，geLocation返回的是上次选点结果
    chooseLocation.setLocation(null);
  },

  handleChange(e) {
    this.setData({
      checked: e.detail.checked,
    });
  },

  click(e) {
    const { trigger } = e.detail;
    console.log('click: ', trigger);
  },

  onShow: function () {
    const location = chooseLocation.getLocation();
    if (location) {
      //经纬度，需要存储到数据库中
      console.log(location.latitude)
      console.log(location.longitude)
      this.setData({
        address: location.address ? location.address : "",
        locationName: location.name ? location.name : "",
        
      });
    }
  },

  showMap() {
    const key = "564BZ-N5WC5-LBFIZ-ISK6L-N3C2O-WJBSQ"; //使用在腾讯位置服务申请的key（必填）
    const referer = "wx6b09b29f03c63446"; //调用插件的app的名称（必填）
    wx.navigateTo({
      url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer
    });
  },

  onColumnChange(e) {
    console.log('picker pick:', e);
  },

  onPickerChange(e) {
    const { key } = e.currentTarget.dataset;
    const { value } = e.detail;

    console.log('picker change:', e.detail);
    this.setData({
      [`${key}Visible`]: false,
      [`${key}Value`]: value,
      [`${key}Text`]: value.join(' '),
    });
  },

  onPickerCancel(e) {
    const { key } = e.currentTarget.dataset;
    console.log(e, '取消');
    console.log('picker1 cancel:');
    this.setData({
      [`${key}Visible`]: false,
    });
  },

  onCityPicker() {
    this.setData({ cityVisible: true });
  },
});
